package inf.coach.mobile;


import java.security.Provider;
import java.util.List;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.IBinder;
import android.telephony.TelephonyManager;

public class locationinfo {
    
	private static Location location=null;
	private static LocationManager locationManager=null;
	private static String provider=null;
	private static Criteria criteria=null;
	
	public static Location getLocation(Context context){
		
		
		locationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
		
		criteria = new Criteria();
		criteria.setAccuracy(Criteria.ACCURACY_FINE);
		criteria.setAltitudeRequired(false);
		criteria.setBearingRequired(false);
		criteria.setCostAllowed(true);
		criteria.setPowerRequirement(Criteria.POWER_LOW); 
		
		if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
		{ 	}
			
		provider = locationManager.getBestProvider(criteria,true);
		
		if(provider!=null){
			
			location = locationManager.getLastKnownLocation(provider);
			locationManager.requestLocationUpdates(provider, 10, 1, locationListener);
		}
		return location;
	}
	private final static LocationListener locationListener = new LocationListener() {


		public void onLocationChanged(Location arg0) {
			// TODO Auto-generated method stub
			location=arg0;
		}


		public void onProviderDisabled(String provider) {
			// TODO Auto-generated method stub
			
		}


		public void onProviderEnabled(String provider) {
			// TODO Auto-generated method stub
			
		}


		public void onStatusChanged(String provider, int status, Bundle extras) {
			// TODO Auto-generated method stub
			
		}
	};
	
	
		
}
